package dut.ir.lxb.weibo.main;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import dut.ir.lxb.weibo.bean.UserRelationBean;
import dut.ir.lxb.weibo.db.UserRelationDao;

public class UserRelationTest
{
	
	public static void main(String [] args)
	{
		
		parseUserRelation("C:\\Users\\Baogege\\Desktop\\微博平台\\NLP圈子关注被关注关系.txt");
		UserRelationDao relationDao = UserRelationDao.getInstance();
		relationDao.getFollowList("1792073233");
	}
	
	
	
	public static void parseUserRelation(String file)
	{
		try
		{
			UserRelationDao relationDao = UserRelationDao.getInstance();
			
			BufferedReader br = new BufferedReader(new FileReader(file));
			String line = null;
			while((line = br.readLine()) != null)
			{
				JSONObject jsonObject = new JSONObject(line);
				String uid = jsonObject.getString("uid");
				JSONArray fansList = jsonObject.getJSONArray("myFollowHisFan");
				for (int i = 0; i < fansList.length(); i++)
				{
					String fans = fansList.get(i).toString();
					UserRelationBean urb = new UserRelationBean();
					urb.setUid1(fans);
					urb.setUid2(uid);
					
					relationDao.insertUserRelation(urb);
				}
				
				JSONArray followList = jsonObject.getJSONArray("sameFollow");
				for(int i = 0; i < followList.length(); i++)
				{
					String follow = followList.getString(i).toString();
					UserRelationBean urb = new UserRelationBean();
					urb.setUid1(uid);
					urb.setUid2(follow);
					
					relationDao.insertUserRelation(urb);
				}
				
			}
			
			br.close();
		}
		catch (FileNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JSONException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
	}
	
}
